import scala.io._

object VariantGenerator {
    def main(args: Array[String]) {

    val students = Source.fromFile(args(0), "cp1251").getLines.toList
    val statements = Source.fromFile(args(1), "cp1251").getLines
    val groups = new scala.collection.mutable.ListBuffer[String]
    var counter = 'A'
    while (statements.hasNext) {
        val line = statements.next
        if (line startsWith "\\begin{problem}") {
            var group = ""
            var ln = statements.next
            while (ln != "\\end{problem}") {
                if (ln == "\\begin{variant}") {
                    group += counter
                    counter = (counter + 1).toChar
                }
                ln = statements.next
            }
            groups += group
        }
    }

    val rng = new java.util.Random
    val maxWidth = students.map(_.length).max

    for (student <- students) {
        printf("%-" + (maxWidth + 1) + "s", student)
        for (group <- groups) {
            print(group.charAt(rng.nextInt(group.length)))
        }
        println()
    }

    }
}